package org.usmile.algorithms.huawei.acm;

import java.util.*;

// https://blog.csdn.net/amos_cloud/article/details/129039127
public class _区间连接器 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();
        List<int[]> segments = new ArrayList<>(Arrays.stream(in.substring(1, in.length() - 1)
                .split("],\\[")).map(s -> {
            String[] nums = s.split(",");
            return new int[]{Integer.parseInt(nums[0]), Integer.parseInt(nums[1])};
        }).toList());
        segments.sort((o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0]);
        List<Integer> connectors = new ArrayList<>(Arrays.stream(sc.nextLine()
                        .replaceAll("\\[", "")
                        .replaceAll("]", "").split(","))
                .map(Integer::parseInt)
                .toList());
        connectors.sort(Comparator.comparingInt(o -> o));

        LinkedList<int[]> mergedSegments = new LinkedList<>();
        mergedSegments.add(segments.get(0));
        for (int i = 1; i < segments.size(); i++) {
            int[] lastMerged = mergedSegments.getLast();
            int[] toMerged = segments.get(i);
            if (lastMerged[1] < toMerged[0]) {
                mergedSegments.add(toMerged);
            } else {
                lastMerged[1] = Math.max(lastMerged[1], toMerged[1]);
            }
        }

        int size = mergedSegments.size();
        List<Integer> gaps = new ArrayList<>();
        for (int i = 1; i < mergedSegments.size(); i++) {
            gaps.add(mergedSegments.get(i)[0] - mergedSegments.get(i - 1)[1]);
        }
        gaps.sort(Comparator.comparingInt(o -> o));
        int gapIndex = 0;
        int connectorIndex = 0;
        while (gapIndex < gaps.size() && connectorIndex < connectors.size()) {
            if (gaps.get(gapIndex) <= connectors.get(connectorIndex)) {
                gapIndex ++;
                connectorIndex++;
                size--;
            } else {
                connectorIndex++;
            }
        }

        System.out.println(size);
    }
}
